package com.example.chongwushangcheng.enums;

public enum PostageTypeEnum {

    // 枚举常量
    FREE_SHIPPING(0, "包邮"),
    BUYER_PAYS(1, "买家承担"),
    PARTIALLY_FREE(2, "包邮(新疆，西藏除外)");

    // 成员变量
    private final int code;
    private final String description;

    // 构造函数
    PostageTypeEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    // 获取 code 的方法
    public int getCode() {
        return code;
    }

    // 获取 description 的方法
    public String getDescription() {
        return description;
    }

    // 根据 code 获取对应的枚举对象
    public static PostageTypeEnum fromCode(int code) {
        for (PostageTypeEnum type : PostageTypeEnum.values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        throw new IllegalArgumentException("Invalid code: " + code);
    }
}